//
//  NavigationViewController.swift
//  CopyWB
//
//  Created by imac on 2017/5/12.
//  Copyright © 2017年 iimac. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
    ///重写 push 方法 , 所有的push动作都会调用此方法
    //viewController  是要被push的控制器 
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        //不是栈底控制器才需要隐藏tabbar ， 根控制器不需要
        if childViewControllers.count > 0{
            //判断控制器的类型
            var title = "返回"
            //对不同的级别设置不同的返回按钮的标题
            if childViewControllers.count == 1{
                title = self.childViewControllers.first?.title ?? "fanhui"
            }
            
            if let vc = viewController as? BaseViewController{
                
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, fontSize: 16, target: self, action: #selector(popToPresent) , isBackBtn
                    : true )
            }
            
        
            viewController.hidesBottomBarWhenPushed = true
            
        }
        
        super.pushViewController(viewController, animated: true)
    }
    // pop返回到上一级控制器
    func popToPresent(){
        popViewController(animated: true)
    }

}
